﻿namespace Agent
{
    using OpenVPN.States;
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Threading;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Markup;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Threading;

    [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
    public class ConnectionButton : UserControl, IComponentConnector
    {
        private string a = "";
        private NotePadExited b;
        private EventHandler<EventArgs> c;
        private ImageSource d;
        private string e = "";
        private SynchronizationContext f;
        internal Label g;
        internal ContextMenu h;
        internal MenuItem i;
        internal MenuItem j;
        internal MenuItem k;
        internal Separator l;
        internal MenuItem m;
        internal Image n;
        internal Label o;
        internal Label p;
        internal Label q;
        private bool r;
        [CompilerGenerated]
        private static ConnectionButton s;
        [CompilerGenerated]
        private static ConnectionButton t;
        [CompilerGenerated]
        private static ConnectionButton u;
        [CompilerGenerated]
        private VPNConfig v;
        [CompilerGenerated]
        private bool w;
        [CompilerGenerated]
        private string x;

        public ConnectionButton()
        {
            this.InitializeComponent();
            this.f = new SynchronizationContext();
            this.a();
        }

        private void a()
        {
            this.i.Header = e.c("Show");
            this.j.Header = e.c("ShowLog");
            this.k.Header = e.c("EditConfig");
            this.q.Content = "";
        }

        public void a(EventHandler<EventArgs> A_0)
        {
            EventHandler<EventArgs> handler2;
            EventHandler<EventArgs> c = this.c;
            do
            {
                handler2 = c;
                EventHandler<EventArgs> handler3 = (EventHandler<EventArgs>) Delegate.Remove(handler2, A_0);
                c = Interlocked.CompareExchange<EventHandler<EventArgs>>(ref this.c, handler3, handler2);
            }
            while (c != handler2);
        }

        public void a(NotePadExited A_0)
        {
            NotePadExited exited2;
            NotePadExited b = this.b;
            do
            {
                exited2 = b;
                NotePadExited exited3 = (NotePadExited) Delegate.Combine(exited2, A_0);
                b = Interlocked.CompareExchange<NotePadExited>(ref this.b, exited3, exited2);
            }
            while (b != exited2);
        }

        [CompilerGenerated]
        private void a(object A_0)
        {
            this.a(false);
            this.q.Dispatcher.BeginInvoke(new Action<string>(this.a), DispatcherPriority.Send, new object[] { e.c("Error") });
            b(this);
        }

        private void a(string A_0)
        {
            this.q.Content = A_0;
            this.f.Send(new SendOrPostCallback(this.f), null);
        }

        [EditorBrowsable(EditorBrowsableState.Never), DebuggerNonUserCode]
        private void a(int A_0, object A_1)
        {
            switch (A_0)
            {
                case 1:
                    ((ConnectionButton) A_1).Loaded += new RoutedEventHandler(this.UserControl_Loaded);
                    return;

                case 2:
                    this.g = (Label) A_1;
                    this.g.MouseLeftButtonUp += new MouseButtonEventHandler(this.lblMain_MouseLeftButtonUp);
                    this.g.MouseDoubleClick += new MouseButtonEventHandler(this.lblMain_MouseDoubleClick);
                    return;

                case 3:
                    this.h = (ContextMenu) A_1;
                    return;

                case 4:
                    this.i = (MenuItem) A_1;
                    this.i.Click += new RoutedEventHandler(this.itmShow_Click);
                    return;

                case 5:
                    this.j = (MenuItem) A_1;
                    this.j.Click += new RoutedEventHandler(this.itmLog_Click);
                    return;

                case 6:
                    this.k = (MenuItem) A_1;
                    this.k.Click += new RoutedEventHandler(this.itmEdit_Click);
                    return;

                case 7:
                    this.l = (Separator) A_1;
                    return;

                case 8:
                    this.m = (MenuItem) A_1;
                    this.m.Click += new RoutedEventHandler(this.itmDNS_Click);
                    return;

                case 9:
                    this.n = (Image) A_1;
                    return;

                case 10:
                    this.o = (Label) A_1;
                    return;

                case 11:
                    this.p = (Label) A_1;
                    return;

                case 12:
                    this.q = (Label) A_1;
                    return;
            }
            this.r = true;
        }

        public void b(EventHandler<EventArgs> A_0)
        {
            EventHandler<EventArgs> handler2;
            EventHandler<EventArgs> c = this.c;
            do
            {
                handler2 = c;
                EventHandler<EventArgs> handler3 = (EventHandler<EventArgs>) Delegate.Combine(handler2, A_0);
                c = Interlocked.CompareExchange<EventHandler<EventArgs>>(ref this.c, handler3, handler2);
            }
            while (c != handler2);
        }

        public void b(NotePadExited A_0)
        {
            NotePadExited exited2;
            NotePadExited b = this.b;
            do
            {
                exited2 = b;
                NotePadExited exited3 = (NotePadExited) Delegate.Remove(exited2, A_0);
                b = Interlocked.CompareExchange<NotePadExited>(ref this.b, exited3, exited2);
            }
            while (b != exited2);
        }

        [CompilerGenerated]
        private void b(object A_0)
        {
            this.a(false);
            this.q.Dispatcher.BeginInvoke(new Action<string>(this.a), DispatcherPriority.Send, new object[] { e.c("Disconnecting") });
        }

        [CompilerGenerated]
        private void c(object A_0)
        {
            this.a(false);
            this.q.Dispatcher.BeginInvoke(new Action<string>(this.a), DispatcherPriority.Send, new object[] { "" });
        }

        [CompilerGenerated]
        private void d(object A_0)
        {
            this.a(true);
            this.q.Dispatcher.BeginInvoke(new Action<string>(this.a), DispatcherPriority.Send, new object[] { e.c("Connected") });
            b(this);
        }

        [CompilerGenerated]
        private void e(object A_0)
        {
            this.q.Dispatcher.BeginInvoke(new Action<string>(this.a), DispatcherPriority.Send, new object[] { e.c("Connecting") });
            this.a(false);
            a(this);
        }

        [CompilerGenerated]
        private void f(object A_0)
        {
            if (this.e())
            {
                this.d = this.n.Source;
                this.n.Source = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/shieldconnected.png"));
            }
            else if (this.d != null)
            {
                this.n.Source = this.d;
            }
        }

        public void i()
        {
            ConfigManager.f();
            this.e = "";
        }

        [DebuggerNonUserCode]
        public void InitializeComponent()
        {
            if (!this.r)
            {
                this.r = true;
                Uri resourceLocator = new Uri("/TheSafety;component/connectionbutton.xaml", UriKind.Relative);
                Application.LoadComponent(this, resourceLocator);
            }
        }

        private void itmDNS_Click(object A_0, RoutedEventArgs A_1)
        {
            try
            {
                Clipboard.SetText(this.n());
            }
            catch (Exception exception)
            {
                ConfigManager.a("itmDNS_Click", exception);
            }
        }

        private void itmEdit_Click(object A_0, RoutedEventArgs A_1)
        {
            ProcessStartInfo info = new ProcessStartInfo {
                Arguments = "\"" + this.g().h() + "\"",
                ErrorDialog = true,
                FileName = "notepad.exe",
                UseShellExecute = true
            };
            Process process = new Process {
                StartInfo = info,
                EnableRaisingEvents = true
            };
            process.Exited += new EventHandler(this.NotePad_Exited);
            process.Start();
        }

        private void itmLog_Click(object A_0, RoutedEventArgs A_1)
        {
            ProcessStartInfo info = new ProcessStartInfo {
                Arguments = "\"" + this.g().s() + "\"",
                ErrorDialog = true,
                FileName = "notepad.exe",
                UseShellExecute = true
            };
            new Process { StartInfo = info }.Start();
        }

        private void itmShow_Click(object A_0, RoutedEventArgs A_1)
        {
            using (StatusWindow window = new StatusWindow(this.e, this.g().l().State.CreateSnapshot().ConnectionState))
            {
                window.c(this);
                VPNConfig config1 = this.g();
                config1.b = (EventHandler<TmpFileLogEventArgs>) Delegate.Combine(config1.b, window.b);
                this.g().l().State.StateChanged += new EventHandler<StateChangedEventArgs>(window.SetStatus);
                ConfigManager.a(window);
            }
        }

        public void j()
        {
            this.e = "";
            ConfigManager.f();
            this.g().i();
        }

        public void k()
        {
            if (this.g() != null)
            {
                this.g().l().State.StateChanged += new EventHandler<StateChangedEventArgs>(this.State_StateChanged);
                VPNConfig config1 = this.g();
                config1.b = (EventHandler<TmpFileLogEventArgs>) Delegate.Combine(config1.b, new EventHandler<TmpFileLogEventArgs>(this.Logs_LogEvent));
            }
        }

        public void lblMain_MouseDoubleClick(object A_0, MouseButtonEventArgs A_1)
        {
            this.j();
        }

        public void lblMain_MouseLeftButtonUp(object A_0, MouseButtonEventArgs A_1)
        {
            foreach (ConnectionButton button in ConfigManager.k())
            {
                button.Background = null;
            }
            c(this);
            ImageBrush brush = new ImageBrush {
                ImageSource = new BitmapImage(new Uri("pack://application:,,,/thesafety;component/Resources/bottom_menu_hover.png"))
            };
            base.Background = brush;
            if (this.c != null)
            {
                this.c(this, new EventArgs());
            }
        }

        private void Logs_LogEvent(object A_0, TmpFileLogEventArgs A_1)
        {
            this.e = this.e + A_1.a();
        }

        private void NotePad_Exited(object A_0, EventArgs A_1)
        {
            if (this.b != null)
            {
                this.b(this, new EventArgs());
            }
        }

        private void State_StateChanged(object A_0, StateChangedEventArgs A_1)
        {
            SendOrPostCallback d = null;
            SendOrPostCallback callback2 = null;
            SendOrPostCallback callback3 = null;
            SendOrPostCallback callback4 = null;
            SendOrPostCallback callback5 = null;
            b((ConnectionButton) null);
            a((ConnectionButton) null);
            switch (A_1.NewState.ConnectionState)
            {
                case VPNConnectionState.Initializing:
                    if (d == null)
                    {
                        d = new SendOrPostCallback(this.e);
                    }
                    this.f.Send(d, null);
                    return;

                case VPNConnectionState.Running:
                    if (callback2 == null)
                    {
                        callback2 = new SendOrPostCallback(this.d);
                    }
                    this.f.Send(callback2, null);
                    return;

                case VPNConnectionState.Stopping:
                    if (callback4 == null)
                    {
                        callback4 = new SendOrPostCallback(this.b);
                    }
                    this.f.Send(callback4, null);
                    return;

                case VPNConnectionState.Stopped:
                    if (callback3 == null)
                    {
                        callback3 = new SendOrPostCallback(this.c);
                    }
                    this.f.Send(callback3, null);
                    return;

                case VPNConnectionState.Error:
                    if (callback5 == null)
                    {
                        callback5 = new SendOrPostCallback(this.a);
                    }
                    this.f.Send(callback5, null);
                    return;
            }
        }

        private void UserControl_Loaded(object A_0, RoutedEventArgs A_1)
        {
            if (this.n() == "")
            {
                this.l.Visibility = this.m.Visibility = Visibility.Collapsed;
            }
        }

        public string ConfigFileName
        {
            [CompilerGenerated]
            get
            {
                return this.x;
            }
            [CompilerGenerated]
            set
            {
                this.x = value;
            }
        }

        public static ConnectionButton ConnectedItem
        {
            [CompilerGenerated]
            get
            {
                return t;
            }
            [CompilerGenerated]
            set
            {
                t = value;
            }
        }

        public static ConnectionButton ConnectingItem
        {
            [CompilerGenerated]
            get
            {
                return u;
            }
            [CompilerGenerated]
            set
            {
                u = value;
            }
        }

        public string ConnectionLog
        {
            get
            {
                return this.e;
            }
        }

        public string DNS
        {
            get
            {
                return this.a;
            }
            set
            {
                this.a = value;
                this.m.Header = "DNS: " + value;
            }
        }

        public bool IsConnected
        {
            [CompilerGenerated]
            get
            {
                return this.w;
            }
            [CompilerGenerated]
            set
            {
                this.w = value;
            }
        }

        public static ConnectionButton SelectedItem
        {
            [CompilerGenerated]
            get
            {
                return s;
            }
            [CompilerGenerated]
            set
            {
                s = value;
            }
        }

        public string Text
        {
            get
            {
                return this.o.Content.ToString();
            }
            set
            {
                this.o.Content = value;
            }
        }

        public VPNConfig VPNConfiguration
        {
            [CompilerGenerated]
            get
            {
                return this.v;
            }
            [CompilerGenerated]
            set
            {
                this.v = value;
            }
        }

        public string VPNUserName
        {
            get
            {
                return this.p.Content.ToString();
            }
            set
            {
                this.p.Content = value;
            }
        }
    }
}

